<template>
	<view class="test">
		<div >
			<uv-navbar  :placeholder='true'  >
				<template v-slot:left>
					<view class="title"></view>
				</template>
				<template v-slot:center>
					<view class="title">游戏测试</view>
				</template>
			</uv-navbar>
		</div>
		
		<div class="tabs">
			<div class="item" @click='tabSwicth(index)' v-for="(item,index) in tabs" :key='index'>
				<div :class="['name',currentTab==index && 'active']">{{item.name}}</div>
			</div>
		</div>
		
		<div class="list_box" v-if='currentTab==0'>
			<div class="item" @click='navTo(item,"game")' v-for="(item,index) in gameData.list" :key="index">
				<image class="pic"  :src="item.image" mode=""></image>
				<div class="desc desc2">
					<div class="name">{{item.title}}</div>
					<div class="btn">点击进入</div>
				</div>
			</div>
		</div>
		
		
		<div class="list_box" v-if='currentTab==1'>
			<div class="item" @click='navTo(item,"test")' v-for="(item,index) in questData.list" :key="index">
				<image class="pic2"  :src="item.image" mode=""></image>
				<div class="desc">
					<div class="name">{{item.name}}</div>
					<div class="btn">点击进入</div>
				</div>
			</div>
		</div>
		
	</view>
</template>

<script>
	import { getGameList,getQuestList} from '@/network/api.js'
	import { baseURL } from '@/network/config.js'
	export default {
		data() {
			return {
				currentTab:0,
				tabs:[{name:"游戏"},{name:"测试"}],
				gameData:{
					list:[],
					total:0
				},
				questData:{
					list:[],
					total:0
				},
				query:{ page:1,limit:10},
				
			}
		},
		onShow(){
			// #ifdef H5
			document.title = ' '
			// #endif
		},
		onLoad() {
			// #ifdef H5
			document.title = ' '
			// #endif
			this.getGame(this.query)
			this.getQuest(this.query)
			// #ifdef H5
			document.title = ' '
			// #endif
		},
		methods: {
			tabSwicth(index){
				this.currentTab = index
				this.query.page = 1
				if(index==0){
					this.getGame(this.query)
				}
				if(index==1){
					this.getQuest(this.query)
				}
			},
			navTo(item,type){
				console.log('item:',item)
	
				if(type === 'game'){
					// #ifdef H5
					// if(item.webview && item.url){
					// 	uni.navigateTo({url: `/pages/webview/webview?url=${item.url}`})
					// }
					// if(!item.webview && item.url){
					// 	window.open(item.url)
					// }
					// if(!item.url){
					// 	uni.showToast({title: '没有url',duration: 2000,icon:'none'});
					// }
					uni.showToast({title: '请在微信小程序中进入',duration: 2000,icon:'none'});
					// #endif
					
					// #ifdef MP-WEIXIN
					if(item.appid){
						uni.navigateToMiniProgram({appId: item.appid,path: item.path})
					}else{
						uni.showToast({title: '没有appid',duration: 2000,icon:'none'});
					}
					// #endif
					
				}
				if(type === 'test'){
					uni.navigateTo({url: `/pages/test_form/test_form?id=${item.id}&tit=${item.name}`})
				}
			
			},
			async getGame(query){
				const {data} = await getGameList(query)
				const list = data.list.map(i=>({...i, image:`${baseURL}${i.image}`}))
				data.list = list
				this.gameData = data
			},
			async getQuest(query){
				const {data} = await getQuestList(query)
				const list = data.list.map(i=>({...i, image:`${baseURL}${i.image}`}))
				data.list = list
				this.questData = data
			},
		}
	}
</script>

<style lang="less" scoped>
	.title{
		font-weight: bold;
	}
.tabs{
	display: flex;
	align-items: center;
	height: 60rpx;
	.item{
		flex:1;
		display: flex;
		justify-content: center;
		align-items: center;
		.name{
			font-size: 28rpx;
			font-weight: 400;
			color: #828282;
			position: relative;
			padding: 0 5rpx;
		}
	}
	.active{
		&::before{
			content: '';
			position: absolute;
			right: 0;
			left: 0;
			bottom:-10rpx;
			height: 5rpx;
			background: #4E6FD9;
			border-radius: 2rpx;
		}
		&.name{
			color:#4E6FD9;
		}
	}
	
}
.list_box{
		border-top:1px solid #EAEAEA;
		margin: 20rpx 25rpx 20rpx 25rpx;
		.item{
			display: flex;
			padding: 33rpx 0;
			border-bottom:1px solid #EAEAEA;
			&:last-child{
				border:none;
			}
			.pic{
				// width: 340rpx;
				width: 210rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.pic2{
				width: 340rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.desc2{
				margin-left: 50rpx;
			}
			.desc{			
				flex:1;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding-left: 30rpx;
				.name{
					font-size: 30rpx;
					font-weight: bold;
					color: #343434;
					margin-top: 10rpx;
				}
				.btn{
					width: 200rpx;
					height: 60rpx;
					background: #4E6FD9;
					border-radius: 30rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 28rpx;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
		}
	}
</style>
